package com.woniuxy.cloud.userassembly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.cloud.entity.TUserServiceProcess;
import com.woniuxy.cloud.form.AddUserServiceProcessForm;
import com.woniuxy.cloud.userassembly.mapper.TUserServiceProcessMapper;
import com.woniuxy.cloud.userassembly.service.ITUserServiceProcessService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class TUserServiceProcessServiceImpl extends ServiceImpl<TUserServiceProcessMapper, TUserServiceProcess> implements ITUserServiceProcessService {


    /**
     * 根据订单详情id查询服务流程
     * @param orderDetailId 订单详情id
     * @return
     */
    @Override
    public List<TUserServiceProcess> getUserServiceProcessesList(Integer orderDetailId) {
        QueryWrapper<TUserServiceProcess> wrapper = new QueryWrapper<>();
        wrapper.eq("user_service_process_service_order_detail_id",orderDetailId);
        return getBaseMapper().selectList(wrapper);
    }



    /**
     * 修改服务流程状态为开始
     * @param userServiceProcessId 用户服务流程id
     * @return
     */
    @Override
    public Integer updateUserServiceProcessStatus(Integer userServiceProcessId) {
        UpdateWrapper<TUserServiceProcess> wrapper = new UpdateWrapper<>();
        wrapper.eq("user_service_process_id",userServiceProcessId).set("user_service_process_status",1);
        return getBaseMapper().update(null,wrapper);
    }

    /**
     * 修改服务状态为结束
     * @param userServiceProcessId 用户服务流程id
     * @param date 完成时间
     * @return Integer
     */
    @Override
    public Integer updateUserServiceProcessStatusOver(Integer userServiceProcessId, Date date) {
        UpdateWrapper<TUserServiceProcess> wrapper = new UpdateWrapper<>();
        wrapper.eq("user_service_process_id",userServiceProcessId).set("user_service_process_status",2).set("user_service_process_finish_time",date);
        return getBaseMapper().update(null,wrapper);
    }

    /**
     * 新增服务流程
     * @param addUserServiceProcessForm
     * @return  Integer
     */
    @Override
    public Integer insertUserServiceProcess(AddUserServiceProcessForm addUserServiceProcessForm) {
        TUserServiceProcess tUserServiceProcess = new TUserServiceProcess();
        tUserServiceProcess.setUserServiceProcessServiceOrderDetailId(addUserServiceProcessForm.getUserServiceProcessServiceOrderDetailId());
        tUserServiceProcess.setUserServiceProcessSecondServiceId(addUserServiceProcessForm.getUserServiceProcessSecondServiceId());
         tUserServiceProcess.setUserServiceProcessServiceProcessId(addUserServiceProcessForm.getUserServiceProcessServiceProcessId());
         tUserServiceProcess.setUserServiceProcessStatus(0);
        return getBaseMapper().insert(tUserServiceProcess);
    }


}
